package Week6;

import java.util.ArrayList;
import java.util.Iterator;


public class PolyLine implements Geometry{
	//A PolyLine is defined with an ArrayList of Points.
	
	//member variables
	protected ArrayList<Point> polypoints;
	
	//constructor
	public PolyLine(){
		polypoints = new ArrayList<Point>();
	}
	
	//add point method harnessing the array list method
	public boolean add(Point newPoint) {return polypoints.add(newPoint);}
	
	//iterate through points in the array and print them harnessing iterator from arraylists
	public void printAll(){
		Iterator<Point> itr = polypoints.iterator(); 
		while(itr.hasNext()) {
			System.out.print(itr.next() + " ");
		}
	}

	public double computeArea() {
		return 0;
	}

	public double computeLength() {
		double totalLength = 0, segmentLength = 0;
		for(int i=0; i<polypoints.size()-1; i++){
        	segmentLength = 
        			Math.pow(
        					(
        						( Math.pow(polypoints.get(i).getX() - polypoints.get(i+1).getX(), 2) ) +
        						( Math.pow(polypoints.get(i).getY() - polypoints.get(i+1).getY(), 2) )
        						)
        					, 0.5);
        	totalLength = totalLength + segmentLength;
        }

		return totalLength;
	}

	public int computeDimension() {
		int dimension;
		if (polypoints.size() == 1){
			dimension = 0;}
		else if (polypoints.size() == 2){ 	//Should probably also check for equal slope between points
			dimension =  1;}
		else { 								//Should probably also check for equal slope between points
			dimension =  2;}
		return dimension;
	}

	//Getters and setters
	
	public ArrayList<Point> getPolypoints() {
		return polypoints;
	}

	public void setPolypoints(ArrayList<Point> polypoints) {
		this.polypoints = polypoints;
	}	
	
	
	
}
	


